package com.bs.dao.impl;

import java.sql.Types;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;
import org.springframework.jdbc.core.JdbcTemplate;

import com.bs.dao.CompanyInfoDao;


/**
 * 公司介绍 dao
 * @author swp
 * 2016-11-27 18:58:09
 */
@Repository
public class CompanyInfoDaoImpl implements CompanyInfoDao{
	@Autowired 
	JdbcTemplate jdbcTemplate;
	
	
	
	@Override
	public List<Map<String,Object>> getDB(Map<String, String> map){
	
		StringBuffer sql = new StringBuffer();
		sql.append("  SELECT * ");
		sql.append("    FROM company_info ");
		sql.append("   WHERE DELSIGN='0' ");
		
		if(map.get("comName")!=null&&!"".equals(map.get("comName"))){
			sql.append(" AND COM_NAME LIKE '%"+map.get("comName")+"%' ");
		}
		return jdbcTemplate.queryForList(sql.toString());
	}
	
	@Override
	public boolean insert(Map<String,String> map){
		String sql = "INSERT INTO company_info(COM_NO,COM_NAME,PROFILE,IMG_PATH,STORDE,DELSIGN,EDTM) "
				+ "VALUES(?,?,?,?,?,?,?)";
		
		Object[] args = new Object[]{map.get("COM_NO"),map.get("COM_NAME"),map.get("PROFILE"),map.get("IMG_PATH"),map.get("STORDE"),map.get("DELSIGN"),map.get("EDTM")};
		int[] types = new int[]{Types.VARCHAR,Types.VARCHAR,Types.VARCHAR,Types.VARCHAR,Types.VARCHAR,Types.VARCHAR,Types.VARCHAR,};
		try {
			int i = jdbcTemplate.update(sql, args, types);
			if((i>0)) return true;
		} catch (Exception e) {
			e.printStackTrace();
		}
		return false;
	}
	
	@Override
	public boolean update(Map<String,String> map){
		try{
			String deleteSql="UPDATE company_info SET COM_NAME = ?,SET PROFILE=?,IMG_PATH=?,STORDE=?,EDTM=? WHERE ID = ?";
			int i = jdbcTemplate.update(deleteSql,new Object[] { map.get("COM_NAME"),map.get("PROFILE"),
					map.get("IMG_PATH"),map.get("STORDE"),map.get("EDTM"),map.get("ID")});
			if((i>0)) return true;
		} catch(Exception e){
			e.printStackTrace();
		}
		return false;
	}
	
	@Override
	public boolean delete(String id){
		try{
			String deleteSql="UPDATE company_info SET DELSIGN = '1' WHERE ID = ?";
			int i = jdbcTemplate.update(deleteSql,new Object[] { id });
			if((i>0)) return true;
		} catch(Exception e){
			e.printStackTrace();
		}
		return false;
	}
}
